package com.wf.day_0531.test3;

import java.util.ArrayList;

/**
 * @author mpk
 * @since 2024/5/31 17:21:04
 */

/*//3.在键盘上输入一个字符串，要求将字符串中所包含的每一位数字取出并存储在list中，打印list中所有数字相加的和
 “ab3y8u9”==>20*/

public class Demo {
    public static void main(String[] args) {

        ArrayList<Integer> list = new ArrayList<>();

        String str = "ab3y8u9";

        for (int i = 0; i < str.length(); i++) {
            String substring = str.substring(i, i + 1);
            if (substring.matches("[0-9]")) {
                list.add(Integer.parseInt(substring));
            }
        }
        for (Integer i : list) {

            System.out.println(i);
        }

        System.out.println(list.stream()
                .mapToInt(Integer::intValue)
                .sum());

    }


}
